import time,pymysql
from tkinter import Image

# from PLL import img
from data import db
from selenium import webdriver
from selenium.webdriver.common.by import By

#进入数据库
sql = db('root','yidong666','10.59.9.12','a3mall')

driver=webdriver.Firefox()
driver.get('http://10.59.9.12:7001/')
driver.maximize_window()
time.sleep(3)

#点击去登录
driver.find_element(By.XPATH,'/html/body/div[1]/div/div[2]/ul/li[1]/a').click()
time.sleep(3)
#输入账号
driver.find_element(By.NAME,'username').send_keys('13811033962')
time.sleep(3)
#输入密码
driver.find_element(By.NAME,'password').send_keys('123456')
time.sleep(10)

#执行搜索的语句（放哪都行）
ye = sql.select('select amount from mall_users where username = "13811033962"')
print(ye[0][0])

#点击登录按钮
driver.find_element(By.CLASS_NAME,'finish-btn').click()
time.sleep(5)

#切换窗口
driver.switch_to.window(driver.window_handles[-1])
time.sleep(2)

#断言
dy3=driver.find_element(By.XPATH,'/html/body/div[5]/div[2]/div[1]/div[2]/div[2]/ul/li[4]/span').text
print(dy3.replace('¥ ',''))

#关闭表格
sql.select('FLUSH TABLES')

#进行判断（断言正确跑完全程，错误的话进行报错）
assert float(dy3.replace('¥ ',''))==float(ye[0][0])